//move
function getStyle(obj,name){
	if(obj.currentStyle){
		return obj.currentStyle[name];
	}else{
		return getComputedStyle(obj,false)[name];
	}
}
function move(obj,json,options){
	options = options || {};
	options.duration = options.duration || 2000;
	options.type = options.type || 'ease-out';
	var timer = null;
	var start = {};
	var dis = {};
	for(var name in json){
		start[name] = parseFloat(getStyle(obj,name));
		dis[name] = json[name] - start[name];  		
	} 
	var count = Math.floor(options.duration/30);
	var n = 0;
	clearInterval(obj.timer);
	obj.timer = setInterval(function(){
		n++;
		for(var name in json){
			switch(options.type){
				case 'linear':
					var a = n/count;
					var cur = start[name]+dis[name]*a;
					break;
				case 'ease-in':
					var a = n/count;
					var cur = start[name]+dis[name]*a*a*a;
					break;
				case 'ease-out':
					var a = 1-(n/count);
					var cur = start[name]+dis[name]*(1-a*a*a);
					break;
			}
			if(name == 'opacity'){
				obj.style.opacity = cur;
				obj.style.filter = 'alpha(opacity="cur*100")';
			}else{
				obj.style[name] = cur+'px';
			}
		}
		if(n==count){
			clearInterval(obj.timer);
			options.complete && options.complete.apply(obj,arguments);
		}
	},30)
	
}
function getByClass(oParent,sClass){
	if(oParent.getElementsByClassName){
		return oParent.getElementsByClassName(sClass);
	}else{
		var reg = new RegExp('\\b'+sClass+'\\b');
		var arr = [];
		var aEle = oParent.getElementsByTagName('*');
		for(var i = 0; i < aEle.length; i++){
			if(reg.test(aEle[i].className)){
				arr.push(aEle[i]);
			}
		}
		return arr;
	}
}
window.onload = function(){
	//p9
	var oPre = document.getElementById('pre');
	var oNext = document.getElementById('next');
	var oPosBox = document.getElementById('posBox');
	var iNow = 0;
	oPre.onclick = function(){		
		iNow++;
		if(iNow == 6){
			iNow=0;
			move(oPosBox,{left:-200*iNow},{duration:1000});
		}else if(iNow<0){
			move(oPosBox,{left:200*iNow},{duration:1000});
		}else if(iNow>=0){
			move(oPosBox,{left:-200*iNow},{duration:1000});
		}
	};
	oNext.onclick = function(){
		iNow--;
		if(iNow == -6){
			iNow=0;
			move(oPosBox,{left:200*iNow},{duration:1000});
		}else if(iNow<=0){
			move(oPosBox,{left:200*iNow},{duration:1000});
		}else if(iNow>0){
			move(oPosBox,{left:-200*iNow},{duration:1000});
		}
	};
	var aBcontent1 = getByClass(document.body,'box-content');
	var aBcontent2 = getByClass(document.body,'box-content2');
	var aRoll = getByClass(document.body,'roll');	
	
	if(window.navigator.userAgent.indexOf('MSIE 8.0') != -1 || window.navigator.userAgent.indexOf('MSIE 9.0') != -1){
		//teacher
		for(var i = 0; i < aRoll.length;i++){
			aBcontent1[i].style.display = 'none';
			aBcontent2[i].style.display = 'block';
			aRoll[i].index = i;
			aRoll[i].onmouseover = function(){
				move(aBcontent2[this.index],{top:0});
			};
			aRoll[i].onmouseout = function(){
				move(aBcontent2[this.index],{top:-470});
			};
		}
	}else{
		for(var i = 0; i < aRoll.length;i++){
			aBcontent1[i].style.display = 'block';
			aBcontent2[i].style.display = 'none';
		}
	}
};
/*anchor*/

$(document).ready(function() {
    anchor.init()
});

anchor = {
    init : function()  {
        $("a.anchorLink").click(function () {
            elementClick = $(this).attr("href")
            destination = $(elementClick).offset().top;
            $("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, 1100 );
            return false;
        })
    }
}

$(function(){
	//banner
	var mySwiper1 = new Swiper('#swiper1',{
		pagination : '#pagination1',
		paginationClickable: true,
		loop:true,
		autoplay: 4000,
		speed:1000
	});	
	var mySwiper2 = new Swiper('#swiper2',{
		loop:true,
		autoplay: 2000,
		speed:1000,		
		slidesPerView:6,
		simulateTouch:false,
		mode : 'vertical'
	});	
	var mySwiper3 = new Swiper('#swiper3',{
		paginationClickable: true,
		loop:true,
		autoplay: 2000,
		speed:1000,
		simulateTouch:false
	});	
	
	$('#p2 > li').hover(function(){$(this).addClass('act').siblings().removeClass('act');});
	
	//nav
	$('#nav li').mouseover(function(){	
		$('#nav li').attr('class','fl').eq($(this).index()).attr('class','click fl');
	})
	
	//part5
	$('#content li').mouseover(function(){	
		$('#content li').attr('class','fl').eq($(this).index()).attr('class','act fl');
	})
	//part7
	$('#btn li').mouseover(function(){	
		$('#btn li').attr('class','').eq($(this).index()).attr('class','active');
		$('#txtBox ul').attr('class','').eq($(this).index()).attr('class','on');
		$('#right div').attr('class','').eq($(this).index()).attr('class','goTop');
	})
	//part8
	$('#button li').mouseover(function(){	
		$('#button span').attr('class','').eq($(this).index()).attr('class','on');
		$('#bott ul').attr('class','clearfix').eq($(this).index()).attr('class','clearfix goLeft');
	})
	//p11
	$('#btn2 li').mouseover(function(){	
		$('#btn2 li').attr('class','fl').eq($(this).index()).attr('class','fl opa');	
		$('#conBox div').attr('class','').eq($(this).index()).attr('class','on');	
	})
	//p12
	$('#content2 li').mouseover(function(){	
		$('#content2 li').attr('class','fl').eq($(this).index()).attr('class','fl on');	
	})
	//p13
    var oAll = $('#all');
    var aSpan = $('#all span');
    function all(){
    	moveH(aSpan[0],-396);
	    moveH(aSpan[1],-396);
	    moveH(aSpan[2],-264);
	    moveH(aSpan[3],-308);    	    
	    moveH(aSpan[4],-396);
	    moveH(aSpan[5],-44);
	    moveH(aSpan[6],-396);
	    moveH(aSpan[7],-352); 	    
	    moveH(aSpan[8],-352);
	    moveH(aSpan[9],-264);
	    moveH(aSpan[10],-396);
	    moveH(aSpan[11],-132);   
	    moveH(aSpan[12],-352);
	    moveH(aSpan[13],-176);
	    moveH(aSpan[14],-132);
	    moveH(aSpan[15],-264); 
    }
       
    function moveH(obj,t){
    	move(obj,{backgroundPositionY:t});
    }
    
    a = $(window).height(); //娴忚鍣ㄧ獥鍙ｉ珮搴�  
	$(window).scroll(function() {
		b = $(this).scrollTop();   //椤甸潰婊氬姩鐨勯珮搴�  
		c = oAll.offset().top;    //鍏冪礌璺濈鏂囨。锛坉ocument锛夐《閮ㄧ殑楂樺害 	
		
		
	    if(a+b>c){
	    	all();	    	
	    }
	   //p4
		d = $('#num').offset().top;  
		
		if(a+b>d+200){
			$('#num strong').each(function(index,element){
				f = 200;
				$(element).animate({'height':(f-index*16)+'px'},800);
			})
	    }
	});
	//top
	if( document.getElementById('roll_top')) {
        $('#roll_top').hide();
        $(window).scroll(function () {
            if ($(window).scrollTop() > 300) {
                $('#roll_top').fadeIn(400);
            } else {
                $('#roll_top').fadeOut(0);
            }
        });
        $('#roll_top').click(function () {
            $('html,body').animate({
                scrollTop: '0px'
            }, 300);
        });
    }
})



$('.c14-cont-wenzhang-list').children().click(function(){
		var _i = $(this).index();
		console.log(_i)
		$('.c14-alert-wenzhang').show()
		$('.c14-alert-wenzhang-cont').children().removeClass('active').eq(_i).addClass('active')
	})
	$('.c14-wenzhang-close').click(function(){
		$('.c14-alert-wenzhang').hide()
	})
	$('.c14-cont-mianshi-list').children().click(function(){
		var _i = $(this).index();
		console.log(_i)
		$('.c14-alert-mianshi').show()
		$('.c14-alert-mianshi-cont').children().removeClass('active').eq(_i).addClass('active')
	})
	$('.c14-mianshi-close').click(function(){
		$('.c14-alert-mianshi').hide()
	})


